package com.zbkj.admin.controller.brand;

import com.zbkj.common.annotation.LogControllerAnnotation;
import com.zbkj.common.enums.MethodType;
import com.zbkj.common.model.member.PaidMemberCard;
import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.*;
import com.zbkj.common.response.*;
import com.zbkj.common.result.CommonResult;
import com.zbkj.service.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 全民分红营销活动管理
 +----------------------------------------------------------------------
 */
@Slf4j
@RestController
@RequestMapping("api/admin/brand/marketing/activity/dividend")
@Api(tags = "全民分红营销活动管理")
public class BrandMarketingActivityDividendController {

    @Autowired
    private MarketingActivityService marketingActivityService;
    @Autowired
    private OrderService orderService;
    @Autowired
    private PaidMemberOrderService paidMemberOrderService;
    @Autowired
    private UserBalanceRecordService userBalanceRecordService;
    @Autowired
    private PaidMemberCardService paidMemberCardService;

    @ApiOperation(value = "全民分红基础配置信息获取")
    @RequestMapping(value = "/config/get", method = RequestMethod.GET)
    public CommonResult<DividendConfigVo> getDividendBaseConfig() {
        return CommonResult.success(marketingActivityService.getDividendBaseConfig());
    }

    @ApiOperation(value = "保存全民分红基础配置信息")
    @RequestMapping(value = "/config/edit", method = RequestMethod.POST)
    public CommonResult<Object> updateDividendBaseConfig(@RequestBody @Validated DividendConfigVo voRequest) {
        if (marketingActivityService.updateDividendBaseConfig(voRequest)) {
            return CommonResult.success().setMessage("编辑成功");
        }
        return CommonResult.failed().setMessage("编辑失败");
    }

    @ApiOperation(value = "商品订单分页列表") //配合swagger使用
    @RequestMapping(value = "/order/page/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<ProductOrderPageDataResponse>> getProductOrderList(@Validated ProductOrderSearchRequest request,
                                                                          @ModelAttribute PageParamRequest pageParamRequest) {
        CommonPage<ProductOrderPageDataResponse> res =
                CommonPage.restPage(orderService.getProductOrderList(request, pageParamRequest));
        return CommonResult.success(res);
    }

    @ApiOperation(value = "商品订单总计") //配合swagger使用
    @RequestMapping(value = "/order/stat", method = RequestMethod.GET)
    public CommonResult<ProductOrderStatResponse> getOrderStat(@Validated ProductOrderSearchRequest request,
                                                                            @ModelAttribute PageParamRequest pageParamRequest) {
        return CommonResult.success(orderService.getOrderStat(request));
    }

    @ApiOperation(value = "会员卡订单分页列表") //配合swagger使用
    @RequestMapping(value = "/paid/member/page/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<PaidMemberOrderPageDataResponse>> getPaidMemberOrderList(@Validated DividendPaidMemberOrderSearchRequest request,
                                                                                      @ModelAttribute PageParamRequest pageParamRequest) {
        CommonPage<PaidMemberOrderPageDataResponse> res =
                CommonPage.restPage(paidMemberOrderService.getPaidMemberOrderList(request, pageParamRequest));
        return CommonResult.success(res);
    }

    @ApiOperation(value = "会员卡订单总计") //配合swagger使用
    @RequestMapping(value = "/paid/member/stat", method = RequestMethod.GET)
    public CommonResult<PaidMemberOrderStatResponse> getPaidMemberOrderStat(@Validated DividendPaidMemberOrderSearchRequest request,
                                                                                            @ModelAttribute PageParamRequest pageParamRequest) {
        return CommonResult.success(paidMemberOrderService.getPaidMemberOrderStatPage(request));
    }

    @ApiOperation(value = "用户余额分页列表") //配合swagger使用
    @RequestMapping(value = "/user/balance/page/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<UserBalancePageDataResponse>> getUserBalanceList(@Validated UserBalanceSearchRequest request,
                                                                                            @ModelAttribute PageParamRequest pageParamRequest) {
        CommonPage<UserBalancePageDataResponse> res =
                CommonPage.restPage(userBalanceRecordService.getUserBalanceList(request, pageParamRequest));
        return CommonResult.success(res);
    }

}
